BM.Marker.addInitHook(function () {
    this.over = false;
    this.index = -1;
    this.moveOptions = {
        origin: null,
        timer: null,
        done: 0,
        path: null,
        length: 0
    };
    this.setSpeed = function (speed) {
        this.moveOptions.speed = isNaN(parseFloat(speed)) || parseFloat(speed) <= 0 ? 200 : parseFloat(speed);
    };
    this.getSpeed = function () {
        return this.moveOptions.speed;
    };
    this.moveAlong = function (path, speed) {
        path = path instanceof BM.Polyline ? path : new BM.Polyline(path);
        this.moveOptions.path = path;
        this.moveOptions.length = BM.GeometryUtil.length(path);
        this.moveOptions.speed = isNaN(parseFloat(speed)) || parseFloat(speed <= 0) ? 200 : parseFloat(speed);
        this._move();
    };
    this.pauseMove = function () {
        clearInterval(this.moveOptions.timer);
        this.moveOptions.timer = null;
    };
    this.resumeMove = function () {
        this._move();
    };
    this.stopMove = function () {
        this.pauseMove();
        this.moveOptions.done = 0;
    };
    this.overThen = function (callBack) {
    },
        this._move = function () {
            if (this.moveOptions.timer) return;
            let _t = this;
            var index = -1;
            this.moveOptions.timer = setInterval(function () {
                let done = _t.moveOptions.done;
                done += _t.moveOptions.speed / 1000 * 20;
                // done += _t.moveOptions.speed / 1000 * 20;
                let radio = done / _t.moveOptions.length;

                if (radio >= 1) {
                    // 这段自己加的，超过1就停了
                    radio = 0; done = 0;
                    _t.over = true;
                    _t.stopMove();
                    return
                }
                // radio >= 1 ? (radio = 0, done = 0) : true;
                _t.moveOptions.done = done;
                let p = BM.GeometryUtil.interpolateOnLine(_t._map, _t.moveOptions.path, radio);
                _t.setLatLng(p.latLng);
                let pre_p = _t.moveOptions.path.getLatLngs()[p.predecessor];
                if (index !== p.predecessor) {
                    index = p.predecessor;
                    _t.index = p.predecessor;
                }
                if (pre_p) {
                    let passed = _t.moveOptions.path.getLatLngs().slice(0, p.predecessor + 1);
                    passed.push(p.latLng);
                    _t.fire('update_position', { path: passed });
                    let deg = BM.GeometryUtil.computeAngle(_t._map.project(pre_p), _t._map.project(p.latLng))
                    _t._icon.style.transformOrigin = '50% 50%';
                    // _t._icon.style.transform += ' rotateZ(' + deg + 'deg)';
                }
            }, 20);
        }
});